import { 
	login, 
	register, 
	getUserInfo, 
	getOwnCollectionList, 
	updateUserInfo, 
	updateUserAvatar, 
	updateUserAuth, 
	getUserAuthInfo, 
	applyUserAuth,
	updateUserSafePwd,
	updateUserEmail,
	updateHomeStatus,
	updateCollectionStatus,
	getOwnCollectionDetail,
	queryBankList,
	queryMarketList,
	submitWithdraw,
	queryFundList,
	queryWithdrawList,
	queryFollowList,
	queryArtistList,
	queryAccountList,
	queryLikeList,
	createSellOrder
} from '@/common/config/api';
import { LOGIN, REGISTER, LOGOUT } from './../mutations_type'
const user = {
	state: {
		token: ''
	},

	mutations: {
		[LOGIN](state, token) {
			state.token = token
			uni.setStorageSync('Tang_token', token)
		},
		[LOGOUT](state, token) {
			state.token = ''
			uni.removeStorageSync('Tang_token')
		},
	},

	actions: {
		initLoginState({ commit }){
			let token = uni.getStorageSync('Tang_token')
			//console.log('initLoginState: ', token)
			if(token){
				commit(LOGIN, token)
			}
		},
		login({ commit }, data) {
		  return new Promise((resolve, reject) => {
		    login(data).then(res => {
				commit(LOGIN, res.data.token)
				resolve()
		    }).catch(error => {
				reject(error)
		    })
		  })
		},
		logout({ commit }){
			commit(LOGOUT)
		},
		register({ commit }, data) {
			return register(data)
		},
		getUserInfo({ commit }) {
			return getUserInfo()
		},
		getOwnCollectionList({ commit }, data) {
			return getOwnCollectionList(data)
		},
		updateUserInfo({ commit }, data) {
			return updateUserInfo(data)
		},
		updateUserAvatar({ commit }, data) {
			return updateUserAvatar(data)
		},
		updateUserAuth({ commit }, data) {
			return updateUserAuth(data)
		},
		applyUserAuth({ commit }, data) {
			return applyUserAuth(data)
		},
		getUserAuthInfo({ commit }, data) {
			return getUserAuthInfo(data)
		},
		updateUserSafePwd({ commit }, data) {
			return updateUserSafePwd(data)
		},
		updateUserEmail({ commit }, data) {
			return updateUserEmail(data)
		},
		updateHomeStatus({ commit }, data) {
			return updateHomeStatus(data)
		},
		updateCollectionStatus({ commit }, data) {
			return updateCollectionStatus(data)
		},
		getOwnCollectionDetail({ commit }, data) {
			return getOwnCollectionDetail(data)
		},
		queryBankList({ commit }, data) {
			return queryBankList(data)
		},
		queryMarketList({ commit }, data) {
			return queryMarketList(data)
		},
		submitWithdraw({ commit }, data) {
			return submitWithdraw(data)
		},
		queryFundList({ commit }, data) {
			return queryFundList(data)
		},
		queryWithdrawList({commit},data){
			return queryWithdrawList(data)
		},
		queryFollowList({commit},data){
			return queryFollowList(data)
		},
		queryArtistList({commit},data){
			return queryArtistList(data)
		},
		queryAccountList({commit},data){
			return queryAccountList(data)
		},
		queryLikeList({commit},data){
			return queryLikeList(data)
		},
		createSellOrder({commit},data){
			return createSellOrder(data)
		},
	}
}

export default user
